﻿using System;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Interop;
using SessionHunter.Utilities;

namespace SessionHunter.Views
{
    /// <summary>
    /// View for ReferencesViewModel
    /// </summary>
    public partial class ReferencesView : Window
    {
        /// <summary>
        /// Initializes a new instance of the References class.
        /// </summary>
        public ReferencesView()
        {
            SourceInitialized += MainWindow_SourceInitialized;
            InitializeComponent();
        }

        #region Remove close button - from http://julmar.com/blog/mark/?p=17
        private const int GWL_STYLE = -16;
        private const int WS_SYSMENU = 0X00080000;

        [DllImport("user32.dll")]
        private extern static int SetWindowLong(IntPtr hwnd, int index, int value);
        [DllImport("user32.dll")]
        private extern static int GetWindowLong(IntPtr hwnd, int index);

        /// <summary>
        /// Removes the close button, but keeps all of the other maximize/minimize functionality
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        void MainWindow_SourceInitialized(object sender, EventArgs e)
        {
            WindowInteropHelper wih = new WindowInteropHelper(this);
            int style = GetWindowLong(wih.Handle, GWL_STYLE);
            SetWindowLong(wih.Handle, GWL_STYLE, style & ~WS_SYSMENU);
        }
        #endregion

        /// <summary>
        /// Re-sizes the columns when the form loads and when the page is resized
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.SizeChangedEventArgs"/> instance containing the event data.</param>
        private void lstCurrentReferences_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            ListView listView = sender as ListView;
            ListViewHelper.SizeChangedHandler(listView, 0.3, 0.4, 0.3);
        }



        /// <summary>
        /// Re-sizes the columns when the form loads and when the page is resized
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.SizeChangedEventArgs"/> instance containing the event data.</param>
        private void lstMissingAssemblies_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            ListView listView = sender as ListView;
            ListViewHelper.SizeChangedHandler(listView, 1);
        }
    }
}